package ToolPack;

import MaterialPack.CarbonDioxide;
import MaterialPack.Energy;
import MaterialPack.Oxygen;

import java.util.ArrayList;

/**
 * Created by Aaron on 8/10/2014.
 */

public class SpaceSuit implements IWearable {
    private ArrayList<FluidContainer> containers = new ArrayList<>();
    private FluidContainer oxygenTank;
    private float oxygenCapacity = 0.8575f;
    private float initialOxygen = 0.8575f;
    private float oxygenTransferRate = 0.02f;
    private FluidContainer carbonDioxideTank;
    private float carbonDioxideCapacity = 0.1f;
    private float carbonDioxide = 0.0f;
    private float carbonDioxideTransferRate = 0.02f;
    private FluidContainer energyContainer;
    private float energyCapacity = 200.0f;
    private float energy = 200.0f;
    private float energyTransferRate = 4.0f;
    private float energyConsumptionRate = 0.1f;
    private float airConversionRate = 0.02f;
    private float airConversionRatio = 0.5f;

    public SpaceSuit ( ) {
        this.oxygenTank = new FluidContainer(this.oxygenCapacity,
                                             this.oxygenTransferRate,
                                             Oxygen.class,
                                             this.initialOxygen);
        this.carbonDioxideTank = new FluidContainer(this.carbonDioxideCapacity,
                                                    this.carbonDioxideTransferRate,
                                                    CarbonDioxide.class,
                                                    this.carbonDioxide);
        this.energyContainer = new FluidContainer(this.energyCapacity,
                                          this.energyTransferRate,
                                          Energy.class,
                                          this.energy);
        this.containers.add(this.oxygenTank);
        this.containers.add(this.carbonDioxideTank);
        this.containers.add(this.energyContainer);
    }

    public ArrayList<FluidContainer> getContainers ( ) {
        return this.containers;
    }

    public FluidContainer getOxygenTank ( ) {
        return this.oxygenTank;
    }

    public float getOxygen ( ) {
        return this.oxygenTank.getFluid();
    }

    public float getOxygenPercent ( ) {
        return this.oxygenTank.getFluid() / this.oxygenTank.getFluidCapacity();
    }

    public FluidContainer getEnergyContainer() {
        return this.energyContainer;
    }

    public float getEnergy ( ) {
        return this.energyContainer.getFluid();
    }

    public float getEnergyPercent ( ) {
        return this.energyContainer.getFluid() / this.energyContainer.getFluidCapacity();
    }

    public float useOxygen (float amountToUse) {
        return this.oxygenTank.removeFluid(amountToUse);
    }

    public float useEnergy (float amountToUse) {
        return this.energyContainer.removeFluid(amountToUse);
    }

    public void addCarbonDioxide (float amountToAdd) {
        this.carbonDioxideTank.addFluid(amountToAdd);
    }

    public void performSystemFunctions ( ) {
        if (useEnergy(this.energyConsumptionRate) < this.energyConsumptionRate) {
            return;
        }

        float co2Converted = this.carbonDioxideTank.removeFluid(this.airConversionRate);
        this.oxygenTank.addFluid(airConversionRatio * co2Converted);

    }
}
